{
 "cells": [
  {
   "cell_type": "code",
   "id": "initial_id",
   "metadata": {
    "collapsed": true,
    "ExecuteTime": {
     "end_time": "2025-05-22T15:02:31.410100Z",
     "start_time": "2025-05-22T15:02:31.379727Z"
    }
   },
   "source": [
    "{\n",
    " \"cells\": [\n",
    "  {\n",
    "   \"metadata\": {\n",
    "    \"ExecuteTime\": {\n",
    "     \"end_time\": \"2025-05-08T07:25:07.203051Z\",\n",
    "     \"start_time\": \"2025-05-08T07:25:07.171384Z\"\n",
    "    }\n",
    "   },\n",
    "   \"cell_type\": \"code\",\n",
    "   \"source\": [\n",
    "    \"#全连接神经网络\\n\",\n",
    "    \"import tensorflow as tf\\n\",\n",
    "    \"from tensorflow.keras.models import Sequential\\n\",\n",
    "    \"from tensorflow.keras.layers import Dense\\n\",\n",
    "    \"\\n\",\n",
    "    \"# 定义全连接神经网络模型\\n\",\n",
    "    \"def create_mlp(input_shape, output_units):\\n\",\n",
    "    \"    model = Sequential([\\n\",\n",
    "    \"        Dense(64, activation='relu', input_shape=(input_shape,)),\\n\",\n",
    "    \"        Dense(64, activation='relu'),\\n\",\n",
    "    \"        Dense(output_units, activation='softmax')\\n\",\n",
    "    \"    ])\\n\",\n",
    "    \"    return model\\n\",\n",
    "    \"\\n\",\n",
    "    \"# 示例：用于分类问题的MLP\\n\",\n",
    "    \"input_shape = 10  # 输入特征的维度\\n\",\n",
    "    \"output_units = 3  # 输出类别数\\n\",\n",
    "    \"\\n\",\n",
    "    \"mlp_model = create_mlp(input_shape, output_units)\\n\",\n",
    "    \"mlp_model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])\\n\",\n",
    "    \"\\n\",\n",
    "    \"# 打印模型结构\\n\",\n",
    "    \"mlp_model.summary()\\n\"\n",
    "   ],\n",
    "   \"id\": \"41efc93cd7fadeb1\",\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"\\u001B[1mModel: \\\"sequential_3\\\"\\u001B[0m\\n\"\n",
    "      ],\n",
    "      \"text/html\": [\n",
    "       \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\"><span style=\\\"font-weight: bold\\\">Model: \\\"sequential_3\\\"</span>\\n\",\n",
    "       \"</pre>\\n\"\n",
    "      ]\n",
    "     },\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"display_data\"\n",
    "    },\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\\n\",\n",
    "       \"┃\\u001B[1m \\u001B[0m\\u001B[1mLayer (type)                   \\u001B[0m\\u001B[1m \\u001B[0m┃\\u001B[1m \\u001B[0m\\u001B[1mOutput Shape          \\u001B[0m\\u001B[1m \\u001B[0m┃\\u001B[1m \\u001B[0m\\u001B[1m      Param #\\u001B[0m\\u001B[1m \\u001B[0m┃\\n\",\n",
    "       \"┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\\n\",\n",
    "       \"│ dense_6 (\\u001B[38;5;33mDense\\u001B[0m)                 │ (\\u001B[38;5;45mNone\\u001B[0m, \\u001B[38;5;34m64\\u001B[0m)             │           \\u001B[38;5;34m704\\u001B[0m │\\n\",\n",
    "       \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
    "       \"│ dense_7 (\\u001B[38;5;33mDense\\u001B[0m)                 │ (\\u001B[38;5;45mNone\\u001B[0m, \\u001B[38;5;34m64\\u001B[0m)             │         \\u001B[38;5;34m4,160\\u001B[0m │\\n\",\n",
    "       \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
    "       \"│ dense_8 (\\u001B[38;5;33mDense\\u001B[0m)                 │ (\\u001B[38;5;45mNone\\u001B[0m, \\u001B[38;5;34m3\\u001B[0m)              │           \\u001B[38;5;34m195\\u001B[0m │\\n\",\n",
    "       \"└─────────────────────────────────┴────────────────────────┴───────────────┘\\n\"\n",
    "      ],\n",
    "      \"text/html\": [\n",
    "       \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\">┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\\n\",\n",
    "       \"┃<span style=\\\"font-weight: bold\\\"> Layer (type)                    </span>┃<span style=\\\"font-weight: bold\\\"> Output Shape           </span>┃<span style=\\\"font-weight: bold\\\">       Param # </span>┃\\n\",\n",
    "       \"┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\\n\",\n",
    "       \"│ dense_6 (<span style=\\\"color: #0087ff; text-decoration-color: #0087ff\\\">Dense</span>)                 │ (<span style=\\\"color: #00d7ff; text-decoration-color: #00d7ff\\\">None</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">64</span>)             │           <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">704</span> │\\n\",\n",
    "       \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
    "       \"│ dense_7 (<span style=\\\"color: #0087ff; text-decoration-color: #0087ff\\\">Dense</span>)                 │ (<span style=\\\"color: #00d7ff; text-decoration-color: #00d7ff\\\">None</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">64</span>)             │         <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">4,160</span> │\\n\",\n",
    "       \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
    "       \"│ dense_8 (<span style=\\\"color: #0087ff; text-decoration-color: #0087ff\\\">Dense</span>)                 │ (<span style=\\\"color: #00d7ff; text-decoration-color: #00d7ff\\\">None</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">3</span>)              │           <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">195</span> │\\n\",\n",
    "       \"└─────────────────────────────────┴────────────────────────┴───────────────┘\\n\",\n",
    "       \"</pre>\\n\"\n",
    "      ]\n",
    "     },\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"display_data\"\n",
    "    },\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"\\u001B[1m Total params: \\u001B[0m\\u001B[38;5;34m5,059\\u001B[0m (19.76 KB)\\n\"\n",
    "      ],\n",
    "      \"text/html\": [\n",
    "       \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\"><span style=\\\"font-weight: bold\\\"> Total params: </span><span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">5,059</span> (19.76 KB)\\n\",\n",
    "       \"</pre>\\n\"\n",
    "      ]\n",
    "     },\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"display_data\"\n",
    "    },\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"\\u001B[1m Trainable params: \\u001B[0m\\u001B[38;5;34m5,059\\u001B[0m (19.76 KB)\\n\"\n",
    "      ],\n",
    "      \"text/html\": [\n",
    "       \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\"><span style=\\\"font-weight: bold\\\"> Trainable params: </span><span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">5,059</span> (19.76 KB)\\n\",\n",
    "       \"</pre>\\n\"\n",
    "      ]\n",
    "     },\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"display_data\"\n",
    "    },\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"\\u001B[1m Non-trainable params: \\u001B[0m\\u001B[38;5;34m0\\u001B[0m (0.00 B)\\n\"\n",
    "      ],\n",
    "      \"text/html\": [\n",
    "       \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\"><span style=\\\"font-weight: bold\\\"> Non-trainable params: </span><span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">0</span> (0.00 B)\\n\",\n",
    "       \"</pre>\\n\"\n",
    "      ]\n",
    "     },\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"display_data\"\n",
    "    }\n",
    "   ],\n",
    "   \"execution_count\": 13\n",
    "  },\n",
    "  {\n",
    "   \"metadata\": {\n",
    "    \"ExecuteTime\": {\n",
    "     \"end_time\": \"2025-05-08T07:25:07.252870Z\",\n",
    "     \"start_time\": \"2025-05-08T07:25:07.227057Z\"\n",
    "    }\n",
    "   },\n",
    "   \"cell_type\": \"code\",\n",
    "   \"source\": [\n",
    "    \"#递归神经网络\\n\",\n",
    "    \"import tensorflow as tf\\n\",\n",
    "    \"from tensorflow.keras.models import Sequential\\n\",\n",
    "    \"from tensorflow.keras.layers import SimpleRNN, Dense\\n\",\n",
    "    \"\\n\",\n",
    "    \"# 定义递归神经网络模型\\n\",\n",
    "    \"def create_rnn(input_shape, output_units):\\n\",\n",
    "    \"    model = Sequential([\\n\",\n",
    "    \"        SimpleRNN(64, activation='relu', input_shape=(input_shape, 1)),\\n\",\n",
    "    \"        Dense(output_units, activation='softmax')\\n\",\n",
    "    \"    ])\\n\",\n",
    "    \"    return model\\n\",\n",
    "    \"\\n\",\n",
    "    \"# 示例：用于序列分类问题的RNN\\n\",\n",
    "    \"input_shape = 10  # 序列长度\\n\",\n",
    "    \"output_units = 3  # 输出类别数\\n\",\n",
    "    \"\\n\",\n",
    "    \"rnn_model = create_rnn(input_shape, output_units)\\n\",\n",
    "    \"rnn_model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])\\n\",\n",
    "    \"\\n\",\n",
    "    \"# 打印模型结构\\n\",\n",
    "    \"rnn_model.summary()\\n\"\n",
    "   ],\n",
    "   \"id\": \"49b197d48c022981\",\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"\\u001B[1mModel: \\\"sequential_4\\\"\\u001B[0m\\n\"\n",
    "      ],\n",
    "      \"text/html\": [\n",
    "       \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\"><span style=\\\"font-weight: bold\\\">Model: \\\"sequential_4\\\"</span>\\n\",\n",
    "       \"</pre>\\n\"\n",
    "      ]\n",
    "     },\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"display_data\"\n",
    "    },\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\\n\",\n",
    "       \"┃\\u001B[1m \\u001B[0m\\u001B[1mLayer (type)                   \\u001B[0m\\u001B[1m \\u001B[0m┃\\u001B[1m \\u001B[0m\\u001B[1mOutput Shape          \\u001B[0m\\u001B[1m \\u001B[0m┃\\u001B[1m \\u001B[0m\\u001B[1m      Param #\\u001B[0m\\u001B[1m \\u001B[0m┃\\n\",\n",
    "       \"┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\\n\",\n",
    "       \"│ simple_rnn_1 (\\u001B[38;5;33mSimpleRNN\\u001B[0m)        │ (\\u001B[38;5;45mNone\\u001B[0m, \\u001B[38;5;34m64\\u001B[0m)             │         \\u001B[38;5;34m4,224\\u001B[0m │\\n\",\n",
    "       \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
    "       \"│ dense_9 (\\u001B[38;5;33mDense\\u001B[0m)                 │ (\\u001B[38;5;45mNone\\u001B[0m, \\u001B[38;5;34m3\\u001B[0m)              │           \\u001B[38;5;34m195\\u001B[0m │\\n\",\n",
    "       \"└─────────────────────────────────┴────────────────────────┴───────────────┘\\n\"\n",
    "      ],\n",
    "      \"text/html\": [\n",
    "       \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\">┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\\n\",\n",
    "       \"┃<span style=\\\"font-weight: bold\\\"> Layer (type)                    </span>┃<span style=\\\"font-weight: bold\\\"> Output Shape           </span>┃<span style=\\\"font-weight: bold\\\">       Param # </span>┃\\n\",\n",
    "       \"┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\\n\",\n",
    "       \"│ simple_rnn_1 (<span style=\\\"color: #0087ff; text-decoration-color: #0087ff\\\">SimpleRNN</span>)        │ (<span style=\\\"color: #00d7ff; text-decoration-color: #00d7ff\\\">None</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">64</span>)             │         <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">4,224</span> │\\n\",\n",
    "       \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
    "       \"│ dense_9 (<span style=\\\"color: #0087ff; text-decoration-color: #0087ff\\\">Dense</span>)                 │ (<span style=\\\"color: #00d7ff; text-decoration-color: #00d7ff\\\">None</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">3</span>)              │           <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">195</span> │\\n\",\n",
    "       \"└─────────────────────────────────┴────────────────────────┴───────────────┘\\n\",\n",
    "       \"</pre>\\n\"\n",
    "      ]\n",
    "     },\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"display_data\"\n",
    "    },\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"\\u001B[1m Total params: \\u001B[0m\\u001B[38;5;34m4,419\\u001B[0m (17.26 KB)\\n\"\n",
    "      ],\n",
    "      \"text/html\": [\n",
    "       \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\"><span style=\\\"font-weight: bold\\\"> Total params: </span><span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">4,419</span> (17.26 KB)\\n\",\n",
    "       \"</pre>\\n\"\n",
    "      ]\n",
    "     },\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"display_data\"\n",
    "    },\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"\\u001B[1m Trainable params: \\u001B[0m\\u001B[38;5;34m4,419\\u001B[0m (17.26 KB)\\n\"\n",
    "      ],\n",
    "      \"text/html\": [\n",
    "       \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\"><span style=\\\"font-weight: bold\\\"> Trainable params: </span><span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">4,419</span> (17.26 KB)\\n\",\n",
    "       \"</pre>\\n\"\n",
    "      ]\n",
    "     },\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"display_data\"\n",
    "    },\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"\\u001B[1m Non-trainable params: \\u001B[0m\\u001B[38;5;34m0\\u001B[0m (0.00 B)\\n\"\n",
    "      ],\n",
    "      \"text/html\": [\n",
    "       \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\"><span style=\\\"font-weight: bold\\\"> Non-trainable params: </span><span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">0</span> (0.00 B)\\n\",\n",
    "       \"</pre>\\n\"\n",
    "      ]\n",
    "     },\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"display_data\"\n",
    "    }\n",
    "   ],\n",
    "   \"execution_count\": 14\n",
    "  },\n",
    "  {\n",
    "   \"metadata\": {\n",
    "    \"ExecuteTime\": {\n",
    "     \"end_time\": \"2025-05-08T07:25:07.303743Z\",\n",
    "     \"start_time\": \"2025-05-08T07:25:07.267382Z\"\n",
    "    }\n",
    "   },\n",
    "   \"cell_type\": \"code\",\n",
    "   \"source\": [\n",
    "    \"#卷积神经网络\\n\",\n",
    "    \"import tensorflow as tf\\n\",\n",
    "    \"from tensorflow.keras.models import Sequential\\n\",\n",
    "    \"from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense\\n\",\n",
    "    \"\\n\",\n",
    "    \"# 定义卷积神经网络模型\\n\",\n",
    "    \"def create_cnn(input_shape, output_units):\\n\",\n",
    "    \"    model = Sequential([\\n\",\n",
    "    \"        Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(input_shape)),\\n\",\n",
    "    \"        MaxPooling2D(pool_size=(2, 2)),\\n\",\n",
    "    \"        Conv2D(64, kernel_size=(3, 3), activation='relu'),\\n\",\n",
    "    \"        MaxPooling2D(pool_size=(2, 2)),\\n\",\n",
    "    \"        Flatten(),\\n\",\n",
    "    \"        Dense(128, activation='relu'),\\n\",\n",
    "    \"        Dense(output_units, activation='softmax')\\n\",\n",
    "    \"    ])\\n\",\n",
    "    \"    return model\\n\",\n",
    "    \"\\n\",\n",
    "    \"# 示例：用于图像分类问题的CNN\\n\",\n",
    "    \"input_shape = (64, 64, 3)  # 输入图像的尺寸和通道数\\n\",\n",
    "    \"output_units = 10  # 输出类别数\\n\",\n",
    "    \"\\n\",\n",
    "    \"cnn_model = create_cnn(input_shape, output_units)\\n\",\n",
    "    \"cnn_model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])\\n\",\n",
    "    \"\\n\",\n",
    "    \"# 打印模型结构\\n\",\n",
    "    \"cnn_model.summary()\\n\"\n",
    "   ],\n",
    "   \"id\": \"4646de43c8df3876\",\n",
    "   \"outputs\": [\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"\\u001B[1mModel: \\\"sequential_5\\\"\\u001B[0m\\n\"\n",
    "      ],\n",
    "      \"text/html\": [\n",
    "       \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\"><span style=\\\"font-weight: bold\\\">Model: \\\"sequential_5\\\"</span>\\n\",\n",
    "       \"</pre>\\n\"\n",
    "      ]\n",
    "     },\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"display_data\"\n",
    "    },\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\\n\",\n",
    "       \"┃\\u001B[1m \\u001B[0m\\u001B[1mLayer (type)                   \\u001B[0m\\u001B[1m \\u001B[0m┃\\u001B[1m \\u001B[0m\\u001B[1mOutput Shape          \\u001B[0m\\u001B[1m \\u001B[0m┃\\u001B[1m \\u001B[0m\\u001B[1m      Param #\\u001B[0m\\u001B[1m \\u001B[0m┃\\n\",\n",
    "       \"┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\\n\",\n",
    "       \"│ conv2d_2 (\\u001B[38;5;33mConv2D\\u001B[0m)               │ (\\u001B[38;5;45mNone\\u001B[0m, \\u001B[38;5;34m62\\u001B[0m, \\u001B[38;5;34m62\\u001B[0m, \\u001B[38;5;34m32\\u001B[0m)     │           \\u001B[38;5;34m896\\u001B[0m │\\n\",\n",
    "       \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
    "       \"│ max_pooling2d_2 (\\u001B[38;5;33mMaxPooling2D\\u001B[0m)  │ (\\u001B[38;5;45mNone\\u001B[0m, \\u001B[38;5;34m31\\u001B[0m, \\u001B[38;5;34m31\\u001B[0m, \\u001B[38;5;34m32\\u001B[0m)     │             \\u001B[38;5;34m0\\u001B[0m │\\n\",\n",
    "       \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
    "       \"│ conv2d_3 (\\u001B[38;5;33mConv2D\\u001B[0m)               │ (\\u001B[38;5;45mNone\\u001B[0m, \\u001B[38;5;34m29\\u001B[0m, \\u001B[38;5;34m29\\u001B[0m, \\u001B[38;5;34m64\\u001B[0m)     │        \\u001B[38;5;34m18,496\\u001B[0m │\\n\",\n",
    "       \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
    "       \"│ max_pooling2d_3 (\\u001B[38;5;33mMaxPooling2D\\u001B[0m)  │ (\\u001B[38;5;45mNone\\u001B[0m, \\u001B[38;5;34m14\\u001B[0m, \\u001B[38;5;34m14\\u001B[0m, \\u001B[38;5;34m64\\u001B[0m)     │             \\u001B[38;5;34m0\\u001B[0m │\\n\",\n",
    "       \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
    "       \"│ flatten_1 (\\u001B[38;5;33mFlatten\\u001B[0m)             │ (\\u001B[38;5;45mNone\\u001B[0m, \\u001B[38;5;34m12544\\u001B[0m)          │             \\u001B[38;5;34m0\\u001B[0m │\\n\",\n",
    "       \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
    "       \"│ dense_10 (\\u001B[38;5;33mDense\\u001B[0m)                │ (\\u001B[38;5;45mNone\\u001B[0m, \\u001B[38;5;34m128\\u001B[0m)            │     \\u001B[38;5;34m1,605,760\\u001B[0m │\\n\",\n",
    "       \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
    "       \"│ dense_11 (\\u001B[38;5;33mDense\\u001B[0m)                │ (\\u001B[38;5;45mNone\\u001B[0m, \\u001B[38;5;34m10\\u001B[0m)             │         \\u001B[38;5;34m1,290\\u001B[0m │\\n\",\n",
    "       \"└─────────────────────────────────┴────────────────────────┴───────────────┘\\n\"\n",
    "      ],\n",
    "      \"text/html\": [\n",
    "       \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\">┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\\n\",\n",
    "       \"┃<span style=\\\"font-weight: bold\\\"> Layer (type)                    </span>┃<span style=\\\"font-weight: bold\\\"> Output Shape           </span>┃<span style=\\\"font-weight: bold\\\">       Param # </span>┃\\n\",\n",
    "       \"┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\\n\",\n",
    "       \"│ conv2d_2 (<span style=\\\"color: #0087ff; text-decoration-color: #0087ff\\\">Conv2D</span>)               │ (<span style=\\\"color: #00d7ff; text-decoration-color: #00d7ff\\\">None</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">62</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">62</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">32</span>)     │           <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">896</span> │\\n\",\n",
    "       \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
    "       \"│ max_pooling2d_2 (<span style=\\\"color: #0087ff; text-decoration-color: #0087ff\\\">MaxPooling2D</span>)  │ (<span style=\\\"color: #00d7ff; text-decoration-color: #00d7ff\\\">None</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">31</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">31</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">32</span>)     │             <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">0</span> │\\n\",\n",
    "       \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
    "       \"│ conv2d_3 (<span style=\\\"color: #0087ff; text-decoration-color: #0087ff\\\">Conv2D</span>)               │ (<span style=\\\"color: #00d7ff; text-decoration-color: #00d7ff\\\">None</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">29</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">29</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">64</span>)     │        <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">18,496</span> │\\n\",\n",
    "       \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
    "       \"│ max_pooling2d_3 (<span style=\\\"color: #0087ff; text-decoration-color: #0087ff\\\">MaxPooling2D</span>)  │ (<span style=\\\"color: #00d7ff; text-decoration-color: #00d7ff\\\">None</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">14</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">14</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">64</span>)     │             <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">0</span> │\\n\",\n",
    "       \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
    "       \"│ flatten_1 (<span style=\\\"color: #0087ff; text-decoration-color: #0087ff\\\">Flatten</span>)             │ (<span style=\\\"color: #00d7ff; text-decoration-color: #00d7ff\\\">None</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">12544</span>)          │             <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">0</span> │\\n\",\n",
    "       \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
    "       \"│ dense_10 (<span style=\\\"color: #0087ff; text-decoration-color: #0087ff\\\">Dense</span>)                │ (<span style=\\\"color: #00d7ff; text-decoration-color: #00d7ff\\\">None</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">128</span>)            │     <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">1,605,760</span> │\\n\",\n",
    "       \"├─────────────────────────────────┼────────────────────────┼───────────────┤\\n\",\n",
    "       \"│ dense_11 (<span style=\\\"color: #0087ff; text-decoration-color: #0087ff\\\">Dense</span>)                │ (<span style=\\\"color: #00d7ff; text-decoration-color: #00d7ff\\\">None</span>, <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">10</span>)             │         <span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">1,290</span> │\\n\",\n",
    "       \"└─────────────────────────────────┴────────────────────────┴───────────────┘\\n\",\n",
    "       \"</pre>\\n\"\n",
    "      ]\n",
    "     },\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"display_data\"\n",
    "    },\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"\\u001B[1m Total params: \\u001B[0m\\u001B[38;5;34m1,626,442\\u001B[0m (6.20 MB)\\n\"\n",
    "      ],\n",
    "      \"text/html\": [\n",
    "       \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\"><span style=\\\"font-weight: bold\\\"> Total params: </span><span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">1,626,442</span> (6.20 MB)\\n\",\n",
    "       \"</pre>\\n\"\n",
    "      ]\n",
    "     },\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"display_data\"\n",
    "    },\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"\\u001B[1m Trainable params: \\u001B[0m\\u001B[38;5;34m1,626,442\\u001B[0m (6.20 MB)\\n\"\n",
    "      ],\n",
    "      \"text/html\": [\n",
    "       \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\"><span style=\\\"font-weight: bold\\\"> Trainable params: </span><span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">1,626,442</span> (6.20 MB)\\n\",\n",
    "       \"</pre>\\n\"\n",
    "      ]\n",
    "     },\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"display_data\"\n",
    "    },\n",
    "    {\n",
    "     \"data\": {\n",
    "      \"text/plain\": [\n",
    "       \"\\u001B[1m Non-trainable params: \\u001B[0m\\u001B[38;5;34m0\\u001B[0m (0.00 B)\\n\"\n",
    "      ],\n",
    "      \"text/html\": [\n",
    "       \"<pre style=\\\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,'DejaVu Sans Mono',consolas,'Courier New',monospace\\\"><span style=\\\"font-weight: bold\\\"> Non-trainable params: </span><span style=\\\"color: #00af00; text-decoration-color: #00af00\\\">0</span> (0.00 B)\\n\",\n",
    "       \"</pre>\\n\"\n",
    "      ]\n",
    "     },\n",
    "     \"metadata\": {},\n",
    "     \"output_type\": \"display_data\"\n",
    "    }\n",
    "   ],\n",
    "   \"execution_count\": 15\n",
    "  }\n",
    " ],\n",
    " \"metadata\": {\n",
    "  \"kernelspec\": {\n",
    "   \"display_name\": \"Python 3\",\n",
    "   \"language\": \"python\",\n",
    "   \"name\": \"python3\"\n",
    "  },\n",
    "  \"language_info\": {\n",
    "   \"codemirror_mode\": {\n",
    "    \"name\": \"ipython\",\n",
    "    \"version\": 2\n",
    "   },\n",
    "   \"file_extension\": \".py\",\n",
    "   \"mimetype\": \"text/x-python\",\n",
    "   \"name\": \"python\",\n",
    "   \"nbconvert_exporter\": \"python\",\n",
    "   \"pygments_lexer\": \"ipython2\",\n",
    "   \"version\": \"2.7.6\"\n",
    "  }\n",
    " },\n",
    " \"nbformat\": 4,\n",
    " \"nbformat_minor\": 5\n",
    "}\n"
   ],
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'cells': [{'metadata': {'ExecuteTime': {'end_time': '2025-05-08T07:25:07.203051Z',\n",
       "     'start_time': '2025-05-08T07:25:07.171384Z'}},\n",
       "   'cell_type': 'code',\n",
       "   'source': ['#全连接神经网络\\n',\n",
       "    'import tensorflow as tf\\n',\n",
       "    'from tensorflow.keras.models import Sequential\\n',\n",
       "    'from tensorflow.keras.layers import Dense\\n',\n",
       "    '\\n',\n",
       "    '# 定义全连接神经网络模型\\n',\n",
       "    'def create_mlp(input_shape, output_units):\\n',\n",
       "    '    model = Sequential([\\n',\n",
       "    \"        Dense(64, activation='relu', input_shape=(input_shape,)),\\n\",\n",
       "    \"        Dense(64, activation='relu'),\\n\",\n",
       "    \"        Dense(output_units, activation='softmax')\\n\",\n",
       "    '    ])\\n',\n",
       "    '    return model\\n',\n",
       "    '\\n',\n",
       "    '# 示例：用于分类问题的MLP\\n',\n",
       "    'input_shape = 10  # 输入特征的维度\\n',\n",
       "    'output_units = 3  # 输出类别数\\n',\n",
       "    '\\n',\n",
       "    'mlp_model = create_mlp(input_shape, output_units)\\n',\n",
       "    \"mlp_model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])\\n\",\n",
       "    '\\n',\n",
       "    '# 打印模型结构\\n',\n",
       "    'mlp_model.summary()\\n'],\n",
       "   'id': '41efc93cd7fadeb1',\n",
       "   'outputs': [{'data': {'text/plain': ['\\x1b[1mModel: \"sequential_3\"\\x1b[0m\\n'],\n",
       "      'text/html': ['<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\\'DejaVu Sans Mono\\',consolas,\\'Courier New\\',monospace\"><span style=\"font-weight: bold\">Model: \"sequential_3\"</span>\\n',\n",
       "       '</pre>\\n']},\n",
       "     'metadata': {},\n",
       "     'output_type': 'display_data'},\n",
       "    {'data': {'text/plain': ['┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\\n',\n",
       "       '┃\\x1b[1m \\x1b[0m\\x1b[1mLayer (type)                   \\x1b[0m\\x1b[1m \\x1b[0m┃\\x1b[1m \\x1b[0m\\x1b[1mOutput Shape          \\x1b[0m\\x1b[1m \\x1b[0m┃\\x1b[1m \\x1b[0m\\x1b[1m      Param #\\x1b[0m\\x1b[1m \\x1b[0m┃\\n',\n",
       "       '┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\\n',\n",
       "       '│ dense_6 (\\x1b[38;5;33mDense\\x1b[0m)                 │ (\\x1b[38;5;45mNone\\x1b[0m, \\x1b[38;5;34m64\\x1b[0m)             │           \\x1b[38;5;34m704\\x1b[0m │\\n',\n",
       "       '├─────────────────────────────────┼────────────────────────┼───────────────┤\\n',\n",
       "       '│ dense_7 (\\x1b[38;5;33mDense\\x1b[0m)                 │ (\\x1b[38;5;45mNone\\x1b[0m, \\x1b[38;5;34m64\\x1b[0m)             │         \\x1b[38;5;34m4,160\\x1b[0m │\\n',\n",
       "       '├─────────────────────────────────┼────────────────────────┼───────────────┤\\n',\n",
       "       '│ dense_8 (\\x1b[38;5;33mDense\\x1b[0m)                 │ (\\x1b[38;5;45mNone\\x1b[0m, \\x1b[38;5;34m3\\x1b[0m)              │           \\x1b[38;5;34m195\\x1b[0m │\\n',\n",
       "       '└─────────────────────────────────┴────────────────────────┴───────────────┘\\n'],\n",
       "      'text/html': ['<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\\'DejaVu Sans Mono\\',consolas,\\'Courier New\\',monospace\">┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\\n',\n",
       "       '┃<span style=\"font-weight: bold\"> Layer (type)                    </span>┃<span style=\"font-weight: bold\"> Output Shape           </span>┃<span style=\"font-weight: bold\">       Param # </span>┃\\n',\n",
       "       '┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\\n',\n",
       "       '│ dense_6 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dense</span>)                 │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">64</span>)             │           <span style=\"color: #00af00; text-decoration-color: #00af00\">704</span> │\\n',\n",
       "       '├─────────────────────────────────┼────────────────────────┼───────────────┤\\n',\n",
       "       '│ dense_7 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dense</span>)                 │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">64</span>)             │         <span style=\"color: #00af00; text-decoration-color: #00af00\">4,160</span> │\\n',\n",
       "       '├─────────────────────────────────┼────────────────────────┼───────────────┤\\n',\n",
       "       '│ dense_8 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dense</span>)                 │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">3</span>)              │           <span style=\"color: #00af00; text-decoration-color: #00af00\">195</span> │\\n',\n",
       "       '└─────────────────────────────────┴────────────────────────┴───────────────┘\\n',\n",
       "       '</pre>\\n']},\n",
       "     'metadata': {},\n",
       "     'output_type': 'display_data'},\n",
       "    {'data': {'text/plain': ['\\x1b[1m Total params: \\x1b[0m\\x1b[38;5;34m5,059\\x1b[0m (19.76 KB)\\n'],\n",
       "      'text/html': ['<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\\'DejaVu Sans Mono\\',consolas,\\'Courier New\\',monospace\"><span style=\"font-weight: bold\"> Total params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">5,059</span> (19.76 KB)\\n',\n",
       "       '</pre>\\n']},\n",
       "     'metadata': {},\n",
       "     'output_type': 'display_data'},\n",
       "    {'data': {'text/plain': ['\\x1b[1m Trainable params: \\x1b[0m\\x1b[38;5;34m5,059\\x1b[0m (19.76 KB)\\n'],\n",
       "      'text/html': ['<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\\'DejaVu Sans Mono\\',consolas,\\'Courier New\\',monospace\"><span style=\"font-weight: bold\"> Trainable params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">5,059</span> (19.76 KB)\\n',\n",
       "       '</pre>\\n']},\n",
       "     'metadata': {},\n",
       "     'output_type': 'display_data'},\n",
       "    {'data': {'text/plain': ['\\x1b[1m Non-trainable params: \\x1b[0m\\x1b[38;5;34m0\\x1b[0m (0.00 B)\\n'],\n",
       "      'text/html': ['<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\\'DejaVu Sans Mono\\',consolas,\\'Courier New\\',monospace\"><span style=\"font-weight: bold\"> Non-trainable params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> (0.00 B)\\n',\n",
       "       '</pre>\\n']},\n",
       "     'metadata': {},\n",
       "     'output_type': 'display_data'}],\n",
       "   'execution_count': 13},\n",
       "  {'metadata': {'ExecuteTime': {'end_time': '2025-05-08T07:25:07.252870Z',\n",
       "     'start_time': '2025-05-08T07:25:07.227057Z'}},\n",
       "   'cell_type': 'code',\n",
       "   'source': ['#递归神经网络\\n',\n",
       "    'import tensorflow as tf\\n',\n",
       "    'from tensorflow.keras.models import Sequential\\n',\n",
       "    'from tensorflow.keras.layers import SimpleRNN, Dense\\n',\n",
       "    '\\n',\n",
       "    '# 定义递归神经网络模型\\n',\n",
       "    'def create_rnn(input_shape, output_units):\\n',\n",
       "    '    model = Sequential([\\n',\n",
       "    \"        SimpleRNN(64, activation='relu', input_shape=(input_shape, 1)),\\n\",\n",
       "    \"        Dense(output_units, activation='softmax')\\n\",\n",
       "    '    ])\\n',\n",
       "    '    return model\\n',\n",
       "    '\\n',\n",
       "    '# 示例：用于序列分类问题的RNN\\n',\n",
       "    'input_shape = 10  # 序列长度\\n',\n",
       "    'output_units = 3  # 输出类别数\\n',\n",
       "    '\\n',\n",
       "    'rnn_model = create_rnn(input_shape, output_units)\\n',\n",
       "    \"rnn_model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])\\n\",\n",
       "    '\\n',\n",
       "    '# 打印模型结构\\n',\n",
       "    'rnn_model.summary()\\n'],\n",
       "   'id': '49b197d48c022981',\n",
       "   'outputs': [{'data': {'text/plain': ['\\x1b[1mModel: \"sequential_4\"\\x1b[0m\\n'],\n",
       "      'text/html': ['<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\\'DejaVu Sans Mono\\',consolas,\\'Courier New\\',monospace\"><span style=\"font-weight: bold\">Model: \"sequential_4\"</span>\\n',\n",
       "       '</pre>\\n']},\n",
       "     'metadata': {},\n",
       "     'output_type': 'display_data'},\n",
       "    {'data': {'text/plain': ['┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\\n',\n",
       "       '┃\\x1b[1m \\x1b[0m\\x1b[1mLayer (type)                   \\x1b[0m\\x1b[1m \\x1b[0m┃\\x1b[1m \\x1b[0m\\x1b[1mOutput Shape          \\x1b[0m\\x1b[1m \\x1b[0m┃\\x1b[1m \\x1b[0m\\x1b[1m      Param #\\x1b[0m\\x1b[1m \\x1b[0m┃\\n',\n",
       "       '┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\\n',\n",
       "       '│ simple_rnn_1 (\\x1b[38;5;33mSimpleRNN\\x1b[0m)        │ (\\x1b[38;5;45mNone\\x1b[0m, \\x1b[38;5;34m64\\x1b[0m)             │         \\x1b[38;5;34m4,224\\x1b[0m │\\n',\n",
       "       '├─────────────────────────────────┼────────────────────────┼───────────────┤\\n',\n",
       "       '│ dense_9 (\\x1b[38;5;33mDense\\x1b[0m)                 │ (\\x1b[38;5;45mNone\\x1b[0m, \\x1b[38;5;34m3\\x1b[0m)              │           \\x1b[38;5;34m195\\x1b[0m │\\n',\n",
       "       '└─────────────────────────────────┴────────────────────────┴───────────────┘\\n'],\n",
       "      'text/html': ['<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\\'DejaVu Sans Mono\\',consolas,\\'Courier New\\',monospace\">┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\\n',\n",
       "       '┃<span style=\"font-weight: bold\"> Layer (type)                    </span>┃<span style=\"font-weight: bold\"> Output Shape           </span>┃<span style=\"font-weight: bold\">       Param # </span>┃\\n',\n",
       "       '┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\\n',\n",
       "       '│ simple_rnn_1 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">SimpleRNN</span>)        │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">64</span>)             │         <span style=\"color: #00af00; text-decoration-color: #00af00\">4,224</span> │\\n',\n",
       "       '├─────────────────────────────────┼────────────────────────┼───────────────┤\\n',\n",
       "       '│ dense_9 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dense</span>)                 │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">3</span>)              │           <span style=\"color: #00af00; text-decoration-color: #00af00\">195</span> │\\n',\n",
       "       '└─────────────────────────────────┴────────────────────────┴───────────────┘\\n',\n",
       "       '</pre>\\n']},\n",
       "     'metadata': {},\n",
       "     'output_type': 'display_data'},\n",
       "    {'data': {'text/plain': ['\\x1b[1m Total params: \\x1b[0m\\x1b[38;5;34m4,419\\x1b[0m (17.26 KB)\\n'],\n",
       "      'text/html': ['<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\\'DejaVu Sans Mono\\',consolas,\\'Courier New\\',monospace\"><span style=\"font-weight: bold\"> Total params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">4,419</span> (17.26 KB)\\n',\n",
       "       '</pre>\\n']},\n",
       "     'metadata': {},\n",
       "     'output_type': 'display_data'},\n",
       "    {'data': {'text/plain': ['\\x1b[1m Trainable params: \\x1b[0m\\x1b[38;5;34m4,419\\x1b[0m (17.26 KB)\\n'],\n",
       "      'text/html': ['<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\\'DejaVu Sans Mono\\',consolas,\\'Courier New\\',monospace\"><span style=\"font-weight: bold\"> Trainable params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">4,419</span> (17.26 KB)\\n',\n",
       "       '</pre>\\n']},\n",
       "     'metadata': {},\n",
       "     'output_type': 'display_data'},\n",
       "    {'data': {'text/plain': ['\\x1b[1m Non-trainable params: \\x1b[0m\\x1b[38;5;34m0\\x1b[0m (0.00 B)\\n'],\n",
       "      'text/html': ['<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\\'DejaVu Sans Mono\\',consolas,\\'Courier New\\',monospace\"><span style=\"font-weight: bold\"> Non-trainable params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> (0.00 B)\\n',\n",
       "       '</pre>\\n']},\n",
       "     'metadata': {},\n",
       "     'output_type': 'display_data'}],\n",
       "   'execution_count': 14},\n",
       "  {'metadata': {'ExecuteTime': {'end_time': '2025-05-08T07:25:07.303743Z',\n",
       "     'start_time': '2025-05-08T07:25:07.267382Z'}},\n",
       "   'cell_type': 'code',\n",
       "   'source': ['#卷积神经网络\\n',\n",
       "    'import tensorflow as tf\\n',\n",
       "    'from tensorflow.keras.models import Sequential\\n',\n",
       "    'from tensorflow.keras.layers import Conv2D, MaxPooling2D, Flatten, Dense\\n',\n",
       "    '\\n',\n",
       "    '# 定义卷积神经网络模型\\n',\n",
       "    'def create_cnn(input_shape, output_units):\\n',\n",
       "    '    model = Sequential([\\n',\n",
       "    \"        Conv2D(32, kernel_size=(3, 3), activation='relu', input_shape=(input_shape)),\\n\",\n",
       "    '        MaxPooling2D(pool_size=(2, 2)),\\n',\n",
       "    \"        Conv2D(64, kernel_size=(3, 3), activation='relu'),\\n\",\n",
       "    '        MaxPooling2D(pool_size=(2, 2)),\\n',\n",
       "    '        Flatten(),\\n',\n",
       "    \"        Dense(128, activation='relu'),\\n\",\n",
       "    \"        Dense(output_units, activation='softmax')\\n\",\n",
       "    '    ])\\n',\n",
       "    '    return model\\n',\n",
       "    '\\n',\n",
       "    '# 示例：用于图像分类问题的CNN\\n',\n",
       "    'input_shape = (64, 64, 3)  # 输入图像的尺寸和通道数\\n',\n",
       "    'output_units = 10  # 输出类别数\\n',\n",
       "    '\\n',\n",
       "    'cnn_model = create_cnn(input_shape, output_units)\\n',\n",
       "    \"cnn_model.compile(optimizer='adam', loss='sparse_categorical_crossentropy', metrics=['accuracy'])\\n\",\n",
       "    '\\n',\n",
       "    '# 打印模型结构\\n',\n",
       "    'cnn_model.summary()\\n'],\n",
       "   'id': '4646de43c8df3876',\n",
       "   'outputs': [{'data': {'text/plain': ['\\x1b[1mModel: \"sequential_5\"\\x1b[0m\\n'],\n",
       "      'text/html': ['<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\\'DejaVu Sans Mono\\',consolas,\\'Courier New\\',monospace\"><span style=\"font-weight: bold\">Model: \"sequential_5\"</span>\\n',\n",
       "       '</pre>\\n']},\n",
       "     'metadata': {},\n",
       "     'output_type': 'display_data'},\n",
       "    {'data': {'text/plain': ['┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\\n',\n",
       "       '┃\\x1b[1m \\x1b[0m\\x1b[1mLayer (type)                   \\x1b[0m\\x1b[1m \\x1b[0m┃\\x1b[1m \\x1b[0m\\x1b[1mOutput Shape          \\x1b[0m\\x1b[1m \\x1b[0m┃\\x1b[1m \\x1b[0m\\x1b[1m      Param #\\x1b[0m\\x1b[1m \\x1b[0m┃\\n',\n",
       "       '┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\\n',\n",
       "       '│ conv2d_2 (\\x1b[38;5;33mConv2D\\x1b[0m)               │ (\\x1b[38;5;45mNone\\x1b[0m, \\x1b[38;5;34m62\\x1b[0m, \\x1b[38;5;34m62\\x1b[0m, \\x1b[38;5;34m32\\x1b[0m)     │           \\x1b[38;5;34m896\\x1b[0m │\\n',\n",
       "       '├─────────────────────────────────┼────────────────────────┼───────────────┤\\n',\n",
       "       '│ max_pooling2d_2 (\\x1b[38;5;33mMaxPooling2D\\x1b[0m)  │ (\\x1b[38;5;45mNone\\x1b[0m, \\x1b[38;5;34m31\\x1b[0m, \\x1b[38;5;34m31\\x1b[0m, \\x1b[38;5;34m32\\x1b[0m)     │             \\x1b[38;5;34m0\\x1b[0m │\\n',\n",
       "       '├─────────────────────────────────┼────────────────────────┼───────────────┤\\n',\n",
       "       '│ conv2d_3 (\\x1b[38;5;33mConv2D\\x1b[0m)               │ (\\x1b[38;5;45mNone\\x1b[0m, \\x1b[38;5;34m29\\x1b[0m, \\x1b[38;5;34m29\\x1b[0m, \\x1b[38;5;34m64\\x1b[0m)     │        \\x1b[38;5;34m18,496\\x1b[0m │\\n',\n",
       "       '├─────────────────────────────────┼────────────────────────┼───────────────┤\\n',\n",
       "       '│ max_pooling2d_3 (\\x1b[38;5;33mMaxPooling2D\\x1b[0m)  │ (\\x1b[38;5;45mNone\\x1b[0m, \\x1b[38;5;34m14\\x1b[0m, \\x1b[38;5;34m14\\x1b[0m, \\x1b[38;5;34m64\\x1b[0m)     │             \\x1b[38;5;34m0\\x1b[0m │\\n',\n",
       "       '├─────────────────────────────────┼────────────────────────┼───────────────┤\\n',\n",
       "       '│ flatten_1 (\\x1b[38;5;33mFlatten\\x1b[0m)             │ (\\x1b[38;5;45mNone\\x1b[0m, \\x1b[38;5;34m12544\\x1b[0m)          │             \\x1b[38;5;34m0\\x1b[0m │\\n',\n",
       "       '├─────────────────────────────────┼────────────────────────┼───────────────┤\\n',\n",
       "       '│ dense_10 (\\x1b[38;5;33mDense\\x1b[0m)                │ (\\x1b[38;5;45mNone\\x1b[0m, \\x1b[38;5;34m128\\x1b[0m)            │     \\x1b[38;5;34m1,605,760\\x1b[0m │\\n',\n",
       "       '├─────────────────────────────────┼────────────────────────┼───────────────┤\\n',\n",
       "       '│ dense_11 (\\x1b[38;5;33mDense\\x1b[0m)                │ (\\x1b[38;5;45mNone\\x1b[0m, \\x1b[38;5;34m10\\x1b[0m)             │         \\x1b[38;5;34m1,290\\x1b[0m │\\n',\n",
       "       '└─────────────────────────────────┴────────────────────────┴───────────────┘\\n'],\n",
       "      'text/html': ['<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\\'DejaVu Sans Mono\\',consolas,\\'Courier New\\',monospace\">┏━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━━━━━━━━━━┳━━━━━━━━━━━━━━━┓\\n',\n",
       "       '┃<span style=\"font-weight: bold\"> Layer (type)                    </span>┃<span style=\"font-weight: bold\"> Output Shape           </span>┃<span style=\"font-weight: bold\">       Param # </span>┃\\n',\n",
       "       '┡━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━━━━━━━━━━╇━━━━━━━━━━━━━━━┩\\n',\n",
       "       '│ conv2d_2 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Conv2D</span>)               │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">62</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">62</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">32</span>)     │           <span style=\"color: #00af00; text-decoration-color: #00af00\">896</span> │\\n',\n",
       "       '├─────────────────────────────────┼────────────────────────┼───────────────┤\\n',\n",
       "       '│ max_pooling2d_2 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">MaxPooling2D</span>)  │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">31</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">31</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">32</span>)     │             <span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> │\\n',\n",
       "       '├─────────────────────────────────┼────────────────────────┼───────────────┤\\n',\n",
       "       '│ conv2d_3 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Conv2D</span>)               │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">29</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">29</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">64</span>)     │        <span style=\"color: #00af00; text-decoration-color: #00af00\">18,496</span> │\\n',\n",
       "       '├─────────────────────────────────┼────────────────────────┼───────────────┤\\n',\n",
       "       '│ max_pooling2d_3 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">MaxPooling2D</span>)  │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">14</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">14</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">64</span>)     │             <span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> │\\n',\n",
       "       '├─────────────────────────────────┼────────────────────────┼───────────────┤\\n',\n",
       "       '│ flatten_1 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Flatten</span>)             │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">12544</span>)          │             <span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> │\\n',\n",
       "       '├─────────────────────────────────┼────────────────────────┼───────────────┤\\n',\n",
       "       '│ dense_10 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dense</span>)                │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">128</span>)            │     <span style=\"color: #00af00; text-decoration-color: #00af00\">1,605,760</span> │\\n',\n",
       "       '├─────────────────────────────────┼────────────────────────┼───────────────┤\\n',\n",
       "       '│ dense_11 (<span style=\"color: #0087ff; text-decoration-color: #0087ff\">Dense</span>)                │ (<span style=\"color: #00d7ff; text-decoration-color: #00d7ff\">None</span>, <span style=\"color: #00af00; text-decoration-color: #00af00\">10</span>)             │         <span style=\"color: #00af00; text-decoration-color: #00af00\">1,290</span> │\\n',\n",
       "       '└─────────────────────────────────┴────────────────────────┴───────────────┘\\n',\n",
       "       '</pre>\\n']},\n",
       "     'metadata': {},\n",
       "     'output_type': 'display_data'},\n",
       "    {'data': {'text/plain': ['\\x1b[1m Total params: \\x1b[0m\\x1b[38;5;34m1,626,442\\x1b[0m (6.20 MB)\\n'],\n",
       "      'text/html': ['<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\\'DejaVu Sans Mono\\',consolas,\\'Courier New\\',monospace\"><span style=\"font-weight: bold\"> Total params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">1,626,442</span> (6.20 MB)\\n',\n",
       "       '</pre>\\n']},\n",
       "     'metadata': {},\n",
       "     'output_type': 'display_data'},\n",
       "    {'data': {'text/plain': ['\\x1b[1m Trainable params: \\x1b[0m\\x1b[38;5;34m1,626,442\\x1b[0m (6.20 MB)\\n'],\n",
       "      'text/html': ['<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\\'DejaVu Sans Mono\\',consolas,\\'Courier New\\',monospace\"><span style=\"font-weight: bold\"> Trainable params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">1,626,442</span> (6.20 MB)\\n',\n",
       "       '</pre>\\n']},\n",
       "     'metadata': {},\n",
       "     'output_type': 'display_data'},\n",
       "    {'data': {'text/plain': ['\\x1b[1m Non-trainable params: \\x1b[0m\\x1b[38;5;34m0\\x1b[0m (0.00 B)\\n'],\n",
       "      'text/html': ['<pre style=\"white-space:pre;overflow-x:auto;line-height:normal;font-family:Menlo,\\'DejaVu Sans Mono\\',consolas,\\'Courier New\\',monospace\"><span style=\"font-weight: bold\"> Non-trainable params: </span><span style=\"color: #00af00; text-decoration-color: #00af00\">0</span> (0.00 B)\\n',\n",
       "       '</pre>\\n']},\n",
       "     'metadata': {},\n",
       "     'output_type': 'display_data'}],\n",
       "   'execution_count': 15}],\n",
       " 'metadata': {'kernelspec': {'display_name': 'Python 3',\n",
       "   'language': 'python',\n",
       "   'name': 'python3'},\n",
       "  'language_info': {'codemirror_mode': {'name': 'ipython', 'version': 2},\n",
       "   'file_extension': '.py',\n",
       "   'mimetype': 'text/x-python',\n",
       "   'name': 'python',\n",
       "   'nbconvert_exporter': 'python',\n",
       "   'pygments_lexer': 'ipython2',\n",
       "   'version': '2.7.6'}},\n",
       " 'nbformat': 4,\n",
       " 'nbformat_minor': 5}"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "execution_count": 1
  },
  {
   "metadata": {},
   "cell_type": "code",
   "outputs": [],
   "execution_count": null,
   "source": "",
   "id": "35d4ba807368998d"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 2
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython2",
   "version": "2.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
